package com.frxuexi.lib_base.net

import android.content.Context
import androidx.room.Room
import com.frxuexi.lib_base.db.CommentDao
import com.frxuexi.lib_base.db.EmpDao
import com.frxuexi.lib_base.db.LatDao
import com.frxuexi.lib_base.db.ParkDatabase
import com.frxuexi.lib_base.db.RepairDao
import com.frxuexi.lib_base.db.UserDao
import com.frxuexi.lib_base.db.VideoDao
import com.frxuexi.lib_base.db.ZanDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {

    @Provides
    @Singleton
    fun getApiService():ApiService=RetrofitUtil.retrofit.create(ApiService::class.java)

    @Provides
    @Singleton
    fun getVideoApiService():VideoApiService=VideoRetrofitUtil.retrofit.create(VideoApiService::class.java)

    @Provides
    @Singleton
    fun initDB(@ApplicationContext context: Context):ParkDatabase{
        return Room.databaseBuilder(context,ParkDatabase::class.java,"park2301.db")
            .allowMainThreadQueries()
            .build()
    }

    @Provides
    @Singleton
    fun getRepairDao(database: ParkDatabase):RepairDao=database.getRepairDao()
    @Provides
    @Singleton
    fun getUserDao(database: ParkDatabase):UserDao=database.getUserDao()

    @Provides
    @Singleton
    fun getEmpDao(database: ParkDatabase):EmpDao=database.getEmpDao()

    @Provides
    @Singleton
    fun getLatDao(database: ParkDatabase):LatDao=database.getLatDao()

    @Provides
    @Singleton
    fun getCommentDao(database: ParkDatabase):CommentDao=database.getCommentDao()

    @Provides
    @Singleton
    fun getZanDao(database: ParkDatabase):ZanDao=database.getZanDao()

    @Provides
    @Singleton
    fun getVideoDao(database: ParkDatabase):VideoDao=database.getVideoDao()
}